/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package irsystem.scenario.method;

import java.util.HashSet;

/**
 *
 * @author Cerulean
 */
public class Normalization
{
    TermVectorSpace words;

    public Normalization(TermVectorSpace words)
    {
        this.words=words;
    }
    
    public TermVectorSpace process()
    {
        double sum = 0;
        for(String term: words.vector.keySet()) {
            sum += Math.pow(words.getValue(term), 2);
        }
        double vectorLength = Math.sqrt(sum);
        for(String term: new HashSet<String>(words.vector.keySet())) {
            words.updateValue(term, words.getValue(term)/vectorLength);
        }
        return words;
    }
}
